package com.interview.spring.annotationConfigApplication;

import java.io.File;

/**
 * @author: zsg
 * @description:
 * @date: 2019/12/8 19:16
 * @modified:
 */
public class AnnotationConfigApplication {

    public void scan(String basePackages){
        String rootPath = this.getClass().getResource("/").getPath();
        String basePackagesPath = basePackages.replaceAll("\\.", "\\\\");

        File file = new File(rootPath + "//" + basePackagesPath);
        for (String fileName : file.list()) {
            System.out.println(fileName);
            String name = fileName.replaceAll(".class", "");

            try {
                Class<?> aClass = Class.forName(basePackages + "." +name);
                if (aClass.isAnnotationPresent(Byteblogs.class)) {
                    System.out.println(aClass.newInstance());
                }
            } catch (ClassNotFoundException | InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }

}
